package com.tanhua.server.controller;

import com.tanhua.server.service.BaiduService;
import com.tanhua.server.service.RecommendUserService;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {


    @Autowired
    private RecommendUserService recommendUserService;

    @Autowired
    private BaiduService baiduService;

    @Autowired
    private TanhuaService tanhuaService;

    /**
     *  GET/tanhua/:id/unlove
     * @param id
     * @return
     */
    @GetMapping(value = "/{id}/unlove" ,name = "左滑不喜欢")
    public ResponseEntity unlove(@PathVariable("id")Integer id){
        return tanhuaService.unlove(id);
    }

    /**
     * GET/tanhua/:id/love
     * @param id
     * @return
     */
    @GetMapping(value = "/{id}/love" ,name = "右滑喜欢")
    public ResponseEntity love(@PathVariable("id")Integer id){
        return tanhuaService.love(id);
    }

    //GET/tanhua/cards
    /**
     * 探花用户列表
     * @return
     */
    @GetMapping(value = "/cards" ,name = "探花用户列表")
    public ResponseEntity cards(){
        return tanhuaService.cards();
    }

    @GetMapping(value = "/search" ,name = "搜附近的人")
    public ResponseEntity search(String gender,Integer distance){
        return baiduService.search(gender,distance);
    }

    @PostMapping(value = "/strangerQuestions" ,name = "回复陌生人的问题")
    public ResponseEntity replyStrangerQuestions( @RequestBody Map map){
//        userId有app传过来是Integer类型，我们想要的是Long类型
        Long userId = Long.parseLong( map.get("userId").toString());
        String reply = (String) map.get("reply");
        return recommendUserService.replyStrangerQuestions(userId,reply);
    }

    @GetMapping(value = "/strangerQuestions" ,name = "查询指定的陌生人问题")
    public ResponseEntity strangerQuestions( Long userId){

        return recommendUserService.strangerQuestions(userId);
    }


    @GetMapping(value = "/{id}/personalInfo" ,name = "查询佳人详情信息")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId){
        return recommendUserService.queryPersonalInfo(userId);
    }

    @GetMapping(value = "/todayBest" ,name = "查询今日最佳推荐人")
    public ResponseEntity todyBest(){
        return recommendUserService.queryTodyBest();
    }


    @GetMapping(value = "/recommendation" ,name = "查询今日推荐列表")
    public ResponseEntity recommendation(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10")  Integer pagesize){
        return recommendUserService.queryRecommendUserList(page,pagesize);
    }
}
